1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 import java.awt.color.ColorSpace;
32 import java.awt.color.ICC_Profile;
33 import java.util.*;
34 import java.nio.*;
35 import java.util.Hashtable;
36
37 public class ReadProfileTest implements Runnable {
38
39 final static int TAG_COUNT_OFFSET = 32;
40
41
42 final static int TAG_ELEM_OFFSET = 33;
43
44 static byte[][] profiles;
45 static int [][] tagSigs;
46 static Hashtable [] tags;
47 boolean status;
48
49 static int [] cspaces = {ColorSpace.CS_sRGB, ColorSpace.CS_PYCC,
50 ColorSpace.CS_LINEAR_RGB, ColorSpace.CS_CIEXYZ,
51 ColorSpace.CS_GRAY};
52
53 static String [] csNames = {"sRGB", "PYCC", "LINEAR_RGB", "CIEXYZ", "GRAY"};
54
55 static void getProfileTags(byte [] data, Hashtable tags) {
56 ByteBuffer byteBuf = ByteBuffer.wrap(data);
57 IntBuffer intBuf = byteBuf.asIntBuffer();
58 int tagCount = intBuf.get(TAG_COUNT_OFFSET);
59 intBuf.position(TAG_ELEM_OFFSET);
60 for (int i = 0; i < tagCount; i++) {
61 int tagSig = intBuf.get();
62 int tagDataOff = intBuf.get();
63 int tagSize = intBuf.get();
64
65 byte [] tagData = new byte[tagSize];
66 byteBuf.position(tagDataOff);
67 byteBuf.get(tagData);
68 tags.put(tagSig, tagData);
69 }
70 }
71
72 static {
73 profiles = new byte[cspaces.length][];
74 tags = new Hashtable[cspaces.length];
75
76 for (int i = 0; i < cspaces.length; i++) {
77 ICC_Profile pf = ICC_Profile.getInstance(cspaces[i]);
78 profiles[i] = pf.getData();
79 tags[i] = new Hashtable();
80 getProfileTags(profiles[i], tags[i]);
81 }
82 }
83
84 public ReadProfileTest() {
85 status = true;
86 }
87
88 public void run() {
89 for (int i = 0; i < cspaces.length; i++) {
90 ICC_Profile pf = ICC_Profile.getInstance(cspaces[i]);
91 byte [] data = pf.getData();
92 if (!Arrays.equals(data, profiles[i])) {
93 status = false;
94 System.err.println("Incorrect result of getData() " + "with " +
95 csNames[i] + " profile");
96 throw new RuntimeException("Incorrect result of getData()");
97 }
98
99 Iterator<Integer> iter = tags[i].keySet().iterator();
100 while(iter.hasNext()) {
101 int tagSig = iter.next();
102 byte [] tagData = pf.getData(tagSig);
103 if (!Arrays.equals(tagData,
104 (byte[]) tags[i].get(tagSig)))
105 {
106 status = false;
107 System.err.println("Incorrect result of getData(int) with" +
108 " tag " +
109 Integer.toHexString(tagSig) +
110 " of " + csNames[i] + " profile");
111
112 throw new RuntimeException("Incorrect result of " +
113 "getData(int)");
114 }
115 }
116 }
117 }
118
119 public boolean getStatus() {
120 return status;
121 }
122
123 public static void main(String [] args) {
124 ReadProfileTest test = new ReadProfileTest();
125 test.run();
126 }
127 }